package facetest.az26;

import org.junit.Test;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * All rights Reserved, Designed By www.rongdasoft.com
 *
 * @version V1.0
 * @Title: CASTest
 * @Description:
 * @author:wsp
 * @date: 2019/10/12
 * @Copyright: 2019/10/12 www.rongdasoft.com
 * Inc. All rights reserved.
 */
public class LinkBolckQueueTest {
    static Thread t1, t2;
    String[] zimuArr = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", ",M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    BlockingQueue<String> b1 = new LinkedBlockingQueue<>();
    BlockingQueue<String> b2 = new LinkedBlockingQueue<>();
    String[] numArr = new String[zimuArr.length];

    {
        for (int i = 0; i < zimuArr.length; i++) {
            numArr[i] = (i + 1) + "";
        }

    }

    @Test
    public void test1() {
        t1 = new Thread(() -> {
            for (String s : zimuArr) {
                try {
                    b2.take();
                    System.out.println(s);
                    b1.put("ok");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t2 = new Thread(() -> {
            for (String s : numArr) {
                try {
                    b2.put("ok");
                    b1.take();
                    System.out.println(s);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        t2.start();
        t1.start();

        while (true) ;

    }
}
